const app = getApp()

const request = (url, method, data, success, complete) => {
  return wx.request({
    url: `${app.globalData.requestPrefix}rest/${url}`,
    header: {
      'content-type': 'application/json',
      'Authorization': app.globalData.authentication
    },
    method: method,
    data: data,
    success: success,
    complete: complete
  })
}

const getRemote = (url, success, data = null) => {
  return request(url, 'GET', data, success)
}
const post = (url, success, data = null) => {
  return request(url, 'POST', data, success)
}

module.exports = {
  request: request,
  get: getRemote,
  post: post
};